/*
 * @Register.java	2008/07/28
 *
 * Copyright 2008 Web & Zen Multimedia, All rights reserved.
 * Use is subject to license terms.
 */
package it.wzm.lightweightlog;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Properties;

/**
 * Where all our Dumper are stored, all extending classes are asked to implement few methods.
 * The register also have a cleanup method, dumper with status 'failure' are removed if they are declared
 * with killonfailure=true.
 */
public abstract class Register<T extends Dumper> extends LightweightlogObject  implements Serializable  {
    
    /**
	 * As required by serialization
	 */
	private static final long serialVersionUID = 1656332533899430608L;
    
    /**
     * Constructor
     * @param p Custom set of properties
     * @param t Array of dumper
     */
    public Register(Properties p, ArrayList<T> t) {
    	super("register",p);
    }
    
    protected void preinit() {
    	
    }

    protected void postinit() {
    	
    }
    
    /**
     * Size of this register
     * @return int
     */
    protected abstract int size();
    
    /**
     * Save dumper to slot
     * @param t extended Dumper
     * @return true if this Dumper is properly saved
     */
    protected abstract boolean save(T t);
    
    /**
     * Remove dumper from slot
     * @param t extended Dumper
     * @return true if this Dumper is properly saved
     */
    protected abstract boolean remove(T t);
    
    /**
     * Dispatch a list of entry to each dumper in this register
     * @param ll A LinkedList of Entry
     */
    protected abstract <E extends Entry> void dispatchToDumper(LinkedList<E> ll);
    
    /**
     * Dispatch an entry to each dumper in this register
     * @param e Any extended Entry
     */
    protected abstract <E extends Entry> void dispatchToDumper(E e);
        
    /**
     * Overriding the inherited method from Object
     * @return String representation for this object
     */
    @Override
    public String toString() {        
        //  returning...
        return super.toString() + " {hc=" + this.hashCode() + "," + this.getStatus() + this.size() + "}" ;
    }
    
}